import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-07-08
 * Time: 20:43
 */
public class Test42 {

    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val,TreeNode left,TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }


    public static TreeNode sortedArrayToBST(int[] num) {
        return sortT(num,0,num.length);
    }

    public static TreeNode sortT(int[] num,int left,int right) {
        if(left >= right) {
            return null;
        }
        int n = num.length;
        int mid = (left + right)/ 2;
        TreeNode root = new TreeNode(num[mid]);
        root.left = sortT(num,left,mid);
        root.right = sortT(num,mid+1,right);
        return root;
    }


    public static List<Integer> levelT(TreeNode root) {
        List<Integer> ret = new ArrayList<>();
        if (root == null) {
            return ret;
        }
        Queue<TreeNode> q = new LinkedList<>();
        q.offer(root);
        while (!q.isEmpty()) {
            int size = q.size();
            while (size > 0) {
                TreeNode node = q.poll();
                if (node != null) {
                    ret.add(node.val);
                    q.offer(node.left);
                    q.offer(node.right);
                } else {
                    ret.add(null);
                }
                size--;
            }
        }
        //移除末尾的null
        while (ret.size() > 0 && ret.get(ret.size() - 1) == null) {
            ret.remove(ret.size() - 1);
        }
        return ret;
    }


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] num = new int[n];
        for(int i = 0; i < n; i++) {
            num[i] = sc.nextInt();
        }
        TreeNode root = sortedArrayToBST(num);
        List<Integer> ret = levelT(root);
        System.out.println(ret);
    }
}
